import ajax from '../../common/js/ajax'
import router from '@ohos.router'
import data_storage from '@ohos.data.storage';
import featureAbility from '@ohos.ability.featureAbility'
import prompt from '@system.prompt';

export default {
    data: {
        phone: '',
        password: '',
        password2: '',
        msg: '',
        code: 0,
        prompt:''
    },
    onInit() {
    },
    onchangePhone(e) {
        this.phone = e.value;
    },
    onchangePassword(e) {
        this.password = e.value;
    },
    onchangePassword2(e) {
        this.password2 = e.value;
    },
    registered() {
        ajax.post({
            url: 'http://124.71.79.186:8081/user/reg',
            data: {
                phone: this.phone,
                password: this.password,
                password2: this.password2,
            },
            success: resp => {
                console.log(JSON.stringify(resp))
                this.code = resp.code
                this.msg = resp.msg
                if (resp.code === 200) {
                    this.prompt = '去登陆'
                }else {
                    this.prompt = '确认'
                }
                this.$element('dialog').show()
            }
        })
    },
    confirm() {
        if (this.code === 200) {
            this.$element('dialog').close()
            router.push({
                url: 'pages/login/login'
            })
        }else {
            this.$element('dialog').close()
        }
    },
    goLogin(){
        router.push({
            url: 'pages/login/login'
        })
    }
}
